#include "chatbubble.h"

ChatBubble::ChatBubble(const QString &text, BubbleType type,bool isTimeLabel, QWidget *parent)
    : QWidget{parent}
{
    if(isTimeLabel){
        QLabel *label = new QLabel(text);
        label->setWordWrap(false); // 自动换行
        label->setTextInteractionFlags(Qt::TextSelectableByMouse); // 支持复制

        label->setStyleSheet(
            "QLabel {"
            "font-family: 'SimSun';"
            "font-size: 20px;"
            "}"
            );

        QHBoxLayout *layout = new QHBoxLayout(this);
        layout->setContentsMargins(0, 0, 0, 0); // 外边距
        layout->addStretch();
        if (type == Myself) {
            layout->addWidget(label, 0, Qt::AlignRight);
        } else {
            layout->insertWidget(0, label, 0, Qt::AlignLeft);
        }
    }else{
        QLabel *label = new QLabel(text);
        label->setWordWrap(true); // 自动换行
        label->setTextInteractionFlags(Qt::TextSelectableByMouse); // 支持复制
        if (type == Myself) {
            label->setStyleSheet(
                "QLabel {"
                "background-color: rgb(194, 230, 255);" // 浅蓝色
                "border-radius: 8px;"
                "padding: 10px 10px;"
                "font-family: 'SimSun';"
                "font-size: 18px;"
                "font-weight: bold;"
                "}"
                );
        } else {
            label->setStyleSheet(
                "QLabel {"
                "background-color: rgb(240, 240, 120);" // 橙黄色
                "border-radius: 8px;"
                "padding: 10px 10px;"
                "font-family: 'SimSun';"
                "font-size: 18px;"
                "font-weight: bold;"
                "}"
                );
        }

        QHBoxLayout *layout = new QHBoxLayout(this);
        layout->setContentsMargins(0, 0, 0, 0); // 外边距
        layout->addStretch();
        if (type == Myself) {
            layout->addWidget(label, 0, Qt::AlignRight);
        } else {
            layout->insertWidget(0, label, 0, Qt::AlignLeft);
        }
    }
}
